import { defineStore } from "pinia";

interface IState {
    open:boolean,
    code:string
}

export const useScannerStore = defineStore({
    // 每个 store 的 id 必须唯一
    id: 'scanner',
    // state 表示数据源
    state: (): IState => ({
        open:false,
        code:""
    }),
    // actions 用来修改 state
    actions: {
        start(){
            this.$patch((state)=>{
                state.open = true
            })
        },
        end(){
            this.$patch((state)=>{
                state.open = false
                state.code = ""
            })
        },
        setCode(code:string){
            this.$patch((state)=>{
                state.code = code
            })
        }
    }
})